import { PageConfig } from 'next';
import an48 from '@mmstudio/an000048';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import getuser from '../../../atoms/getuser';

const logger = anylogger('pages/api/teacher/getname.api');

export type Result = {
	username: string;
	picture: string;
};

/**
 * 获取导师姓名
 */
const handler = an48<Result>();

handler.get(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		const user = await getuser(req);
		res.status(200).json({ username: user?.name, picture: user?.picture });
	} catch (error) {
		logger.error(error);
		res.status(200).json({
			username: '',
			picture: ''
		});
	}
});

export const config = {} as PageConfig;

export default handler;
